package com.fx.smsclient.JsonSerializer;

import com.google.gson.*;
import com.zx.sms.codec.cmpp.msg.CmppDeliverResponseMessage;

import java.lang.reflect.Type;

public class CmppDeliverResponseMessageSerializer implements JsonSerializer<CmppDeliverResponseMessage> {

    static Gson gson = new GsonBuilder().create();

    @Override
    public JsonElement serialize(CmppDeliverResponseMessage src, Type typeOfSrc, JsonSerializationContext context) {
        JsonElement jsonElement = gson.toJsonTree(src);
        JsonObject jsonObject = (JsonObject) jsonElement;
        jsonObject.remove("msgId");
        jsonObject.addProperty("msgId",src.getMsgId().toString());

        jsonObject.remove("header");
        jsonObject.addProperty("commandId",Integer.toUnsignedLong(src.getHeader().getCommandId()));
        jsonObject.addProperty("sequenceId",src.getHeader().getSequenceId());

        return jsonObject;
    }
}
